package com.example.love_margin.Controller;



import com.example.love_margin.Entity.Adopt;
import com.example.love_margin.Service.AdoptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "领养申请",tags = "申请领养宠物")
@RestController
@RequestMapping(value = "/login",name = "我的")
@CrossOrigin
public class AdoptController {

    @Autowired
    AdoptService adoptService;

    //申请领养宠物
    @ApiOperation(value = "申请领养宠物",notes = "申请领养宠物")
    @PostMapping(value = "/applyAdoptPet")
    public Object applyAdoptPet(@RequestBody Adopt adopt){
        return adoptService.addAdopt(adopt);
    }

    //通过领养宠物申请
    @ApiOperation(value = "通过领养宠物申请",notes = "通过领养宠物申请")
    @PostMapping(value = "/passAdoptPet")
    public Object passAdoptPet(@RequestParam int adopt_id){
        return adoptService.updateAdoptState(adopt_id);
    }

    //批量通过领养宠物申请
    @ApiOperation(value = "批量通过领养宠物申请",notes = "批量通过领养宠物申请")
    @PostMapping(value = "/passAdoptPets")
    public Object passAdoptPets(@RequestParam Integer[] adopt_ids){
        return adoptService.updateAdoptStates(adopt_ids);
    }


    //删除领养宠物申请
    @ApiOperation(value = "删除领养宠物申请",notes = "删除领养宠物申请")
    @PostMapping(value = "/deleteAdoptPet")
    public Object deleteAdoptPet(@RequestParam int adopt_id){
        return adoptService.deleteAdopt(adopt_id);
    }

    //批量删除领养宠物申请
    @ApiOperation(value = "批量删除领养宠物申请",notes = "批量删除领养宠物申请")
    @PostMapping(value = "/deleteAdoptPets")
    public Object deleteAdoptPets(@RequestParam Integer[] adopt_ids){
        return adoptService.delAdoptMany(adopt_ids);
    }

    //修改单个宠物申请详情
    @ApiOperation(value = "修改单个宠物申请详情",notes = "修改单个宠物申请详情")
    @PostMapping(value = "/upOneAdopt")
    public Object upOneAdopt(@RequestBody Adopt adopt){
        return adoptService.updateAdopt(adopt);
    }


    //查询领养宠物申请详情
    @ApiOperation(value = "查询领养宠物申请详情",notes = "查询领养宠物申请详情")
    @GetMapping(value = "/selectAdoptPet")
    public Object selectAdoptPet(@RequestParam int adopt_id){
        return adoptService.selectAdoptOne(adopt_id);
    }

    //查询我的领养宠物申请列表
    @ApiOperation(value = "查询我的领养宠物申请列表",notes = "查询我的领养宠物申请列表")
    @GetMapping(value = "/selectMyAdoptPets")
    public Object selectMyAdoptPets(@RequestParam(required = false) int user_id,@RequestParam(required = false) String adopt_state){
        return adoptService.selectMyAdopt(user_id,adopt_state);
    }



    //后台查询领养宠物申请列表
    @ApiOperation(value = "后台查询领养宠物申请列表",notes = "后台查询领养宠物申请列表")
    @GetMapping(value = "/selectAdoptPets")
    public Object selectAdoptPets(@RequestParam(required = false) Integer pageNum,
                                  @RequestParam(required = false) Integer pageSize){
        return adoptService.selectAdoptState(pageNum,pageSize);
    }




}
